def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def closest_prime(num):
    if num < 2:
        return 2
    if is_prime(num):
        return num
    prime_below = num - 1
    prime_above = num + 1
    while not is_prime(prime_below):
        prime_below -= 1
    while not is_prime(prime_above):
        prime_above += 1
    return prime_below if (num - prime_below) <= (prime_above - num) else prime_above

# Словарь для перевода слов в числа
words_to_numbers = {
    'zero': 0,
    'one': 1,
    'two': 2,
    'three': 3,
    'four': 4,
    'five': 5,
    'six': 6,
    'seven': 7,
    'eight': 8,
    'nine': 9
}

input_string = input().strip()
words = input_string.split()

try:
    if len(words) != 3:
        raise ValueError
    number = int(''.join(str(words_to_numbers[word]) for word in words))
    if 100 <= number <= 999:
        print(closest_prime(number))
    else:
        print("Wrong input")
except (KeyError, ValueError):
    print("Wrong input")
